﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class ModifyMmsList : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind_Mms();
        }

        protected void DataBind_Mms()
        {
            this.dlMmsList.DataSource = ServiceLocator.IProjectService.GetNxMmsCollection(int.Parse(Request.QueryString["ProjectId"]));

            this.dlMmsList.DataBind();
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            JavaScript.WriteJs("history.go(-2);", this.Page);
        }

        protected void dlMmsList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                NxMms mms = (NxMms)e.Item.DataItem;

                Label lbMmsContent = (Label)e.Item.FindControl("lbMmsContent");
                if (mms.MmsPic != "")
                {
                    if (mms.MmsPosition == 1)
                    {
                        lbMmsContent.Text = "<img src='" + mms.MmsPic + "' width='100px' height='75px'/><br /><textarea id='txtMmsText' style='overflow:auto;border:1px solid;' readonly cols='20' rows='5'>" + mms.MmsText + "</textarea>";
                    }
                    else
                    {
                        lbMmsContent.Text = "<textarea id='txtMmsText' style='overflow:auto;border:1px solid;' cols='20' readonly rows='5'>" + mms.MmsText + "</textarea><br /><img src='" + mms.MmsPic + "' width='100px' height='75px'/>";
                    }
                }
                else
                {
                    lbMmsContent.Text = mms.MmsText;
                }
                Label lbMmsPage = (Label)e.Item.FindControl("lbMmsPage");
                lbMmsPage.Text = mms.MmsPage.ToString();
                HyperLink hlModiy = (HyperLink)e.Item.FindControl("hlModify");
                hlModiy.NavigateUrl = string.Format("ModifyMMS.aspx?MmsId={0}&ProjectId={1}", mms.MmsId, Request.QueryString["ProjectId"]);
            }
        }

        protected void btnCreateNextPage_Click(object sender, EventArgs e)
        {
            int mmsPage = this.dlMmsList.Items.Count+1;
            int projectId = int.Parse(Request.QueryString["ProjectId"]);
            Response.Redirect("MMSCreate.aspx?MmsPage=" + mmsPage + "&ProjectId=" + projectId);
        }
    }
}
